package com.kangye.learnstudent.controller;

import com.github.pagehelper.PageInfo;
import com.kangye.learnstudent.entity.StudentPaper;
import com.kangye.learnstudent.entity.User;
import com.kangye.learnstudent.service.StudentPaperService;
import com.kangye.learnstudent.util.RedisStorageUtil;
import com.kangye.learnstudent.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.sql.Timestamp;
import java.util.ArrayList;

import java.util.List;

/**
 * @program: learndeduo
 * @description: 学生试卷请求接口
 * @author: 高天乐
 * @create: 2021-05-17 14:04
 **/
@RestController
@CrossOrigin
@RequestMapping("/studentPaper")
public class StudentPaperController {
    @Autowired
    private StudentPaperService studentPaperService;
    @Autowired
    private RedisStorageUtil redisStorageUtil;
    //根据年级和科目查询各科和各年级的试卷
    @RequestMapping("/selStudentPaper")
    public ViewJsonObject<StudentPaper> getselStudentPaper(Integer spGradeId, Integer spSubjectId, Integer page, Integer limit){
        //返回数据
        return studentPaperService.selStudentTest(spGradeId,spSubjectId,page,limit);
    }


    //查询部分试卷信息
    @RequestMapping("/getStudentPaper")
    public ViewJsonObject getStudentPaper(Integer page, Integer limit) {
        User user = (User) redisStorageUtil.getKeyOne("studentUserRedisData");
        return studentPaperService.getStudentPaper(user,page,limit);
    }


    //从redis里取值
    @RequestMapping("/getRedis")
    public ViewJsonObject getRedis(Model model){
        //创建list对象
        List<User> list = new ArrayList<>();
        //从redis里取值
        User user = (User) redisStorageUtil.getKeyOne("studentUserRedisData");
        //添加到list集合里
        list.add(user);
        //json 返回页面
        return new ViewJsonObject(list);
    }
    //根据学生id和卷子的id修改做题试卷的状态(做了卷子了没有)和提交卷子的时间
    @RequestMapping("/seleStudentTestPaperpage")
    public void seleStudentTestPaperpage(Timestamp spSubmitTime,Integer spUserId,Integer spId){
        //设置提交卷子的时间
        spSubmitTime= (new Timestamp(new java.util.Date().getTime()));
        //返回数据
        studentPaperService.seleStudentTestPaperpage(spSubmitTime,spUserId,spId);

    }
}
